import * as allUrls from '../../utils/allUrls'
import {
	getLiveRoom,
	recommend,
	attention
} from "../../api/liveHall.js";

export default {
	name: "liveHall",
	data() {
		return {
			//默认显示12个主播
			personNum: 12,
			test: 0,
			showMoreTitle: '点击加载更多',
			recommendList: [],
			hostInfo: [{
				username: 123,
				name: 123,
			}], //直播大厅主播信息
			pageNum: 1,
			pageSize: 12,
			liveType: null,
			// 关注参数
			attentionParams: {
				userId: null,
				studioId: null,
			},
		}
	},
	inject: ['reload'],
	methods: {
		//点击关注
		clickAttention(studioId) {
			this.attentionParams.studioId = studioId;
			console.log(this.attentionParams)
			attention(this.attentionParams).then(res => {
				if(res.code == 200){
					if (res.msg == "关注成功") {
						this.$message({
							message: '关注成功',
							type: 'success'
						});
					} else {
						this.$message({
							message: '取消关注成功',
							type: 'success'
						});
					}
				}
			})
		},
		//点击查看更多，一次性加6个
		morePerson() {
			this.pageSize += this.personNum;
			this.getHostInfo()
			if (this.pageSize > this.test) {
				this.showMoreTitle = '已经没有更多啦！'
			}
		},
		//切换直播类别
		chouseType(type) {
			this.pageSize = this.personNum;
			this.liveType = type;
			this.getHostInfo()
			if (this.pageSize > this.test) {
				this.showMoreTitle = '已经没有更多啦！'
			}
		},
		toLive(val) {
			this.$router.push({
				path: '/liveRoom',
				query: {
					userType: 'audience',
					hostName: val
				}
			})
		},
		//获取主播列表
		getHostInfo() {
			getLiveRoom({
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				liveType: this.liveType,
			}).then(response => {
				this.hostInfo = response.rows;
				console.log(this.hostInfo)
				this.test = response.rows.length;
			});
		},
		//获取推荐主播列表
		getRecommend() {
			recommend().then(response => {
				this.recommendList = response.rows;
			});
		}
	},
	mounted() {
		this.attentionParams.userId = this.$store.state.user.userid;
		this.getRecommend();
		this.getHostInfo();
	}
}
